package com.hengtiansoft.lfy.fragment;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.hengtiansoft.lfy.LFYApplication;
import com.hengtiansoft.lfy.R;
import com.hengtiansoft.lfy.activity.CollectionActivity;
import com.hengtiansoft.lfy.activity.Kdxf_CustomAudio_VoiceDialogActivity;
import com.hengtiansoft.lfy.activity.Kdxf_VoiceDialogActivity;
import com.hengtiansoft.lfy.activity.LoginActivityV2;
import com.hengtiansoft.lfy.adapter.OnDialogueTalkAdapter;
import com.hengtiansoft.lfy.base.BaseFragment;
import com.hengtiansoft.lfy.chart.activity.VoiceDialogActivity;
import com.hengtiansoft.lfy.constants.Constants;
import com.hengtiansoft.lfy.db.been.OneMobileDB;
import com.hengtiansoft.lfy.entity.CollectEntity;
import com.hengtiansoft.lfy.entity.ServiceResult;
import com.hengtiansoft.lfy.net.NetHelper;
import com.hengtiansoft.lfy.net.NetUtils;
import com.hengtiansoft.lfy.utils.CommonUtils;
import com.hengtiansoft.lfy.utils.Config;
import com.hengtiansoft.lfy.utils.Kdxf_TTSPlayer;
import com.hengtiansoft.lfy.utils.PopUtil;
import com.hengtiansoft.lfy.widget.FirstSoundDialog;
import com.hengtiansoft.lfy.widget.MyToast;
import com.hengtiansoft.lfy.widget.YesNoDialog;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.stmt.DeleteBuilder;
import com.j256.ormlite.stmt.QueryBuilder;
import com.umeng.socialize.media.Constant;
import com.ztspeech.constant.ZTConstant;
import com.ztspeech.translator.ZTTranslator;
import com.ztspeech.translator.interf.ZTTranslatorListener;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 对话画面
 */

public class DialogueTalkFragment extends BaseFragment implements View.OnClickListener {
    private static final int ACTIVITY_RESULT_COLLECT_BTN_LOGIN = 10;
    private ImageView mIvDelete,mIvFirstSound;
           // ,iv_sayand;
    private ListView mLvOneMobileChat;
    private InputMethodManager manager;
    private Context mContext;
    private OnDialogueTalkAdapter onDialogueTalkAdapter;
    private ArrayList<HashMap<String, Object>> mList = new ArrayList<HashMap<String, Object>>();
  //  private TextView tv_speekChinese,tv_speekChinesAndEnglish,tv_speekEnglish;
    private TextView tv_speekChinese,tv_speekEnglish;
    private String transferType;
    private static final int TranslateReturn = 1111;
    private int nowId;
    private int mTouchPosition = -1;
    private int mSubmitPosition = -1;
    private int mcolltionPosition=-1;
    private boolean isTrue = false;
    private String textTask;// 原文
    private List<OneMobileDB> mOneMobileDBList;
    private String direction;// 输入者：left，right+
    private ProgressDialog mPd;
    // 数据库的存储
    private RuntimeExceptionDao<OneMobileDB, Integer> mOneMobileDBDao = null;
    private String url;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContext = getActivity();
        return inflater.inflate(R.layout.fragment_dialogue_talk, container, false);
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //加载数据库
        getDataForOneMobileDB();
        initView();
    }
    private boolean hideEnter = false;
    private void initView() {
        manager = (InputMethodManager) mContext.getSystemService(
                Context.INPUT_METHOD_SERVICE);
        mIvDelete = (ImageView) getView().findViewById(R.id.iv_delete);
        mIvDelete.setOnClickListener(this);
        mIvFirstSound = (ImageView) getView().findViewById(R.id.iv_firstsound);
        mIvFirstSound.setOnClickListener(this);
//        iv_sayand= (ImageView) getView().findViewById(R.id.iv_sayand);
//        iv_sayand.setOnClickListener(this);
        mLvOneMobileChat = (ListView) getView().findViewById(R.id.lv_one_mobile);
        mLvOneMobileChat.setItemsCanFocus(true);
        onDialogueTalkAdapter = new OnDialogueTalkAdapter(getActivity(), mList);
        mLvOneMobileChat.setAdapter(onDialogueTalkAdapter);
        mPd = new ProgressDialog(mContext, ProgressDialog.THEME_HOLO_LIGHT);
        mPd.setCanceledOnTouchOutside(false);
        mPd.setMessage(getString(R.string.is_translating));
        mLvOneMobileChat.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                hideKeyboard();
                return false;
            }
        });
        tv_speekChinese= (TextView) getView().findViewById(R.id.tv_speekChinese);
       // tv_speekChinesAndEnglish= (TextView) getView().findViewById(R.id.tv_speekChinesAndEnglish);
        tv_speekEnglish= (TextView) getView().findViewById(R.id.tv_speekEnglish);
        tv_speekChinese.setOnClickListener(this);
       // tv_speekChinesAndEnglish.setOnClickListener(this);
        tv_speekEnglish.setOnClickListener(this);

        onDialogueTalkAdapter
                .setAdapterListener(new OnDialogueTalkAdapter.OneMobileChatAdapterListener() {

                    @Override
                    public void onPlayer(int position) {
                        if (CommonUtils.isNetWorkConnected(mContext)) {
                            String synText = onDialogueTalkAdapter
                                    .getItem(position).get("translation")
                                    .toString();

                            if (onDialogueTalkAdapter.getItem(position).equals("left")) {
                                transferType = "chen";
                            } else {
                                transferType = "ench";
                            }

                            if (synText.length() <= 0)
                                return;
                            // TTSPlayer.getInstense().TTSPlay(synText);
                            Kdxf_TTSPlayer.getInstense().TTSPlay(synText,transferType,"");
                        } else {
                            Toast.makeText(mContext, getString(R.string.network_error),
                                    Toast.LENGTH_LONG).show();
                        }
                    }

                    @Override
                    public void onPlayerY(int position) {
                        Kdxf_TTSPlayer.getInstense().TTSPlayOpu(onDialogueTalkAdapter
                                .getItem(position).get("voiceurl").toString(), onDialogueTalkAdapter
                                .getItem(position).get("translation").toString());
                    }

                    @Override
                    public void onItemClick(int position) {

                    }

                    @Override
                    public void onSubmitClick(int position) {
                        updateTextAdapter(position);

                    }

                    @Override
                    public void onLongClick(boolean left,final int position, View view) {
                        hideKeyboard();
                        getView().getRootView().requestFocus();
                        PopUtil.showTipPopupWindow(new String[]{},left,view, new PopUtil.MyClickListener() {

                            @Override
                            public void copy(int pos, View v) {
                                Intent intent=new Intent(getActivity(),com.hengtiansoft.lfy.widget.AlertDialog.class);
                                intent.putExtra("title",getString(R.string.copy_data));
                                intent.putExtra("showTitle",getString(R.string.copy_showtitle));
                                intent.putExtra("isCopy",true);
                                intent.putExtra("msg",onDialogueTalkAdapter.getItem(pos)
                                        .get("text").toString() + "\n"
                                        + onDialogueTalkAdapter.getItem(pos)
                                        .get("translation").toString());
                                startActivity(intent);

                            }

                            @Override
                            public void delete(final int pos, View v) {
                                new YesNoDialog.Builder(getActivity())
                                        .setMessage(getString(R.string.delete_title_one))
                                        .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                deleteDataForOneMobileDBByID(onDialogueTalkAdapter.getItem(pos).get("id").toString());
                                                mList.remove(onDialogueTalkAdapter.getItem(pos));
                                                onDialogueTalkAdapter
                                                        .notifyDataSetChanged();
                                                dialog.dismiss();
                                            }
                                        })
                                        .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.dismiss();
                                            }
                                        })
                                        .create().show();
                            }

                            @Override
                            public void collection(int pos, View v) {
                                if( !Config.isUserLogined()){
                                    MyToast.show(getActivity(),getString(R.string.not_logined_tips));
                                    Intent intent = new Intent(getActivity(), LoginActivityV2.class);
                                    startActivityForResult(intent, ACTIVITY_RESULT_COLLECT_BTN_LOGIN);
                                    return ;
                                }else{
                                    mcolltionPosition=pos;
                                        collect(pos);
                                }
                            }
                        },position);
                    }

                    @Override
                    public void onUpdateText(int position) {
                        updateTextAdapter(position);
                    }

                    @Override
                    public void TextChangedListener(int position) {

                    }

                    @Override
                    public void onTouchClick(int position) {
                        if (mTouchPosition != position) {
                            onDialogueTalkAdapter.setIvTraVisible(position);
                            onDialogueTalkAdapter.notifyDataSetChanged();
                            mTouchPosition = position;
                        }
                    }

                });
        mLvOneMobileChat.setSelection(ListView.FOCUS_DOWN);
        getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect rect = new Rect();
                //获取root在窗体的可视区域
                getView().getWindowVisibleDisplayFrame(rect);
                //获取root在窗体的不可视区域高度(被其他View遮挡的区域高度)
                int rootInvisibleHeight = getView().getRootView().getHeight() - rect.bottom;
                if (rootInvisibleHeight < 300) {
                    if(hideEnter) {
                        getView().getRootView().requestFocus();
                        onDialogueTalkAdapter.setIvTraVisible(-1);
                        mTouchPosition=-1;
                        onDialogueTalkAdapter.notifyDataSetChanged();
                        hideEnter=false;
                    }
                }else{

                    hideEnter=true;
                }
            }
        });

    }

    private void updateTextAdapter(int position) {
        //修改
        // getChildAt()使用注意事项http://ahua186186.iteye.com/blog/1830180
        mSubmitPosition = position;
        nowId = (Integer) onDialogueTalkAdapter
                .getItem(position).get("id");
        LinearLayout layout = (LinearLayout) mLvOneMobileChat
                .getChildAt(position - mLvOneMobileChat
                        .getFirstVisiblePosition());
        EditText mEditText = (EditText) layout
                .findViewById(R.id.tv_text);
        if (mEditText.getText().toString() != null
                && !mEditText.getText().toString().equals("")) {
            isTrue = true;
            if (onDialogueTalkAdapter.getItem(position)
                    .get("from").equals("left")) {
                transferType = "chen";
            } else {
                transferType = "ench";
            }
            mPd.show();
            textTask = mEditText.getText().toString();
            if("chen".equals(transferType)){
                ZTTranslator.getTranslatorInstance().setLanguage(ZTConstant.HTTP_LANGUAGE_CHEN);
            }else{
                ZTTranslator.getTranslatorInstance().setLanguage(ZTConstant.HTTP_LANGUAGE_ENCH);
            }
            ZTTranslator.getTranslatorInstance().translate(mTranLisenter,mEditText.getText().toString());
        } else {
            Toast.makeText(mContext, getString(R.string.input_content),
                    Toast.LENGTH_LONG).show();
        }
        mTouchPosition = -1;
        hideKeyboard();
    }

    /**
     * 紫冬翻译回调接口
     */
    private ZTTranslatorListener mTranLisenter = new ZTTranslatorListener() {
        @Override
        public void onResult(String text) {
            mPd.dismiss();
            if (isTrue) {  //写入数据库
                updateDataToOneMobileDB(nowId, textTask, text);
            }
            else {
                setDataToOneMobileDB(textTask, text, direction,url);
            }
            if (LFYApplication.getInstance().getSettingAutoPlayer()) {
                //TTSPlayer.getInstense().TTSPlay(result);
                Kdxf_TTSPlayer.getInstense().TTSPlay(text,transferType,"");
            }
        }

        @Override
        public void onError(int i) {
            if(mPd != null && mPd.isShowing()){
                mPd.dismiss();
            }
            Toast.makeText(getActivity(), "翻译失败,请检查网络！", Toast.LENGTH_SHORT)
                    .show();
          //  Log.d(TAG, "翻译错误,错误码:" + i);
        }
    };
    /**
     * 更新本地数据库
     *
     * @param text
     * @param translation

     */
    public void updateDataToOneMobileDB(int id, String text,
                                        String translation) {
        mOneMobileDBDao = LFYApplication.getHelper(mContext).getOneMobileDao();
        if (null != mOneMobileDBDao) {
            try {
                @SuppressWarnings("rawtypes")
                QueryBuilder builder = mOneMobileDBDao.queryBuilder();
                builder.where().eq("id", id);
                mOneMobileDBList = builder.query();
            } catch (SQLException e) {
                mOneMobileDBList = null;
            }
        }
        if (null != mOneMobileDBList && mOneMobileDBList.size() > 0) {
            OneMobileDB oneMobileDB = new OneMobileDB();
            oneMobileDB.setUsername(mOneMobileDBList
                    .get(mOneMobileDBList.size() - 1).getUsername());
            oneMobileDB.setText(text);
            oneMobileDB.setTranslation(translation);
            oneMobileDB.setDirection(mOneMobileDBList
                    .get(mOneMobileDBList.size() - 1).getDirection());
            oneMobileDB.setId(id);
            LFYApplication.getHelper(mContext).getOneMobileDao()
                    .update(oneMobileDB);
        }
        mList.get(mSubmitPosition).put("text", text);
        mList.get(mSubmitPosition).put("translation", translation);
        onDialogueTalkAdapter.setIvTraVisible(-1);
        onDialogueTalkAdapter.notifyDataSetChanged();
        mPd.dismiss();
    }
    /**
     * 隐藏软键盘
     */
    private void hideKeyboard() {
        if (getActivity().getWindow()
                .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (getActivity().getCurrentFocus() != null)
                manager.hideSoftInputFromWindow(
                        getActivity().getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != getActivity().RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case TranslateReturn:
               /* mList.clear();
                getDataForOneMobileDB();
                onDialogueTalkAdapter.notifyDataSetChanged();*/
                String res = data.getStringExtra("result");
                if (res != null && !res.equals("")) {
                    if (res.equals(Constants.No_RESULT)) {
                        if("ench".equals(transferType)){
                            Toast.makeText(getActivity(), getString(R.string.say_againe),
                                    Toast.LENGTH_SHORT).show();
                        }else {
                            Toast.makeText(getActivity(), getString(R.string.say_again),
                                    Toast.LENGTH_SHORT).show();
                        }
                    } else if (res.equals(Constants.ZR_ERROR)) {
                        Toast.makeText(mContext, getString(R.string.recognition_error), Toast.LENGTH_SHORT)
                                .show();
                    } else if (res.equals(Constants.ZR_STOP_NULL)) {
                        return;
                    } else {
                        url=data.getStringExtra("url");
                        mPd.show();
                        textTask = res;
                        if("chen".equals(transferType)){
                            ZTTranslator.getTranslatorInstance().setLanguage(ZTConstant.HTTP_LANGUAGE_CHEN);
//                        ZTTranslator.getTranslatorInstance().setType("t2tn");
                        }else{
                            ZTTranslator.getTranslatorInstance().setLanguage(ZTConstant.HTTP_LANGUAGE_ENCH);
                        }

                        ZTTranslator.getTranslatorInstance().translate(mTranLisenter,textTask);

                    }
                } else {
                    Toast.makeText(mContext,getString(R.string.recognition_error), Toast.LENGTH_SHORT).show();
                }
                break;
            case ACTIVITY_RESULT_COLLECT_BTN_LOGIN:
                if(mcolltionPosition!=-1)
                collect(mcolltionPosition);
                break;

        }
    }
    //执行收藏/反收藏
    private void collect(final int position){
        HashMap<String, Object> item = onDialogueTalkAdapter.getItem(position);
        NetHelper.collect(getActivity(), 0, item.get("text").toString(), item.get("translation").toString(), "", new NetUtils.NetCallBack<ServiceResult>() {
            @Override
            public void success(ServiceResult rspData) {
                CollectEntity entity = (CollectEntity)rspData;
                if ( entity.getRetcode() == 0) {
                    Toast.makeText(getActivity(),getResources().getString(R.string.collect_success), Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(getActivity(), entity.getMessage(), Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void failed(String msg) {
                Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
            }
        }, CollectEntity.class);
    }
    /**
     * 添加至本地数据库
     *
     * @param text
     * @param translation
     * @param direction
     */
    public void setDataToOneMobileDB(String text, String translation,
                                     String direction,String voiceUrl) {
        String username;
        if(Config.isUserLogined()) {
            username= Config.getUserName();
        }else {
            username = "robot";
        }
        OneMobileDB oneMobileDB = new OneMobileDB();
        oneMobileDB.setUsername(username);
        oneMobileDB.setText(text);
        oneMobileDB.setVoiceurl(voiceUrl);
        oneMobileDB.setTranslation(translation);
        oneMobileDB.setDirection(direction);
        mOneMobileDBDao = LFYApplication.getHelper(mContext).getOneMobileDao();
        if (null != mOneMobileDBDao) {
            mOneMobileDBDao.create(oneMobileDB);
            try {
                @SuppressWarnings("rawtypes")
                QueryBuilder builder = mOneMobileDBDao.queryBuilder();
                builder.where().eq("username", username);
                mOneMobileDBList = builder.query();
            } catch (SQLException e) {
                mOneMobileDBList = null;
            }
        }
        if (null != mOneMobileDBList && mOneMobileDBList.size() > 0) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("text", mOneMobileDBList.get(mOneMobileDBList.size() - 1)
                    .getText());
            map.put("translation", mOneMobileDBList
                    .get(mOneMobileDBList.size() - 1).getTranslation());
            map.put("from", mOneMobileDBList.get(mOneMobileDBList.size() - 1)
                    .getDirection());
            map.put("voiceurl",mOneMobileDBList.get(mOneMobileDBList.size() - 1).getVoiceurl());
            map.put("id",
                    mOneMobileDBList.get(mOneMobileDBList.size() - 1).getId());
            mList.add(map);
            onDialogueTalkAdapter.notifyDataSetChanged();
            mLvOneMobileChat.setSelection(ListView.FOCUS_DOWN);
        }
        mPd.dismiss();
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_speekChinese:
                ZTTranslator.getTranslatorInstance().cancelTranslate();
                transferType = "chen";
                direction = "left";
//                startActivityForResult(
//                        new Intent(mContext, Kdxf_VoiceDialogActivity.class)
//                                .putExtra("transferType", transferType),
//                        TranslateReturn);
                startActivityForResult(
                        new Intent(mContext, VoiceDialogActivity.class)
                                .putExtra("transferType", transferType),
                        TranslateReturn);
                break;
//            case R.id.tv_speekChinesAndEnglish:
//                ZTTranslator.getTranslatorInstance().cancelTranslate();
//                startActivityForResult(
//                        new Intent(mContext, Kdxf_CustomAudio_VoiceDialogActivity.class),
//                        TranslateReturn);
//                break;
            case R.id.tv_speekEnglish:
                ZTTranslator.getTranslatorInstance().cancelTranslate();
                transferType = "ench";
                direction = "right";
//                startActivityForResult(
//                        new Intent(mContext, Kdxf_VoiceDialogActivity.class)
//                                .putExtra("transferType", transferType),
//                        TranslateReturn);
                startActivityForResult(
                        new Intent(mContext, VoiceDialogActivity.class)
                                .putExtra("transferType", transferType),
                        TranslateReturn);
                break;
            case R.id.iv_firstsound:
                new FirstSoundDialog.Builder(self).create().show();
                break;
//            case R.id.iv_sayand:
//                startActivityForResult(
//                        new Intent(mContext, Kdxf_CustomAudio_VoiceDialogActivity.class),
//                        TranslateReturn);
//                break;
            case R.id.iv_delete:

               new YesNoDialog.Builder(getActivity())
                        .setMessage(getString(R.string.delete_title))
                        .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                deleteDataForOneMobileDB();
                                mList.clear();
                                onDialogueTalkAdapter
                                        .notifyDataSetChanged();
                                dialog.dismiss();
                            }
                        })
                        .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        })
                        .create().show();
                break;
        }
    }
    /**
     * 根据用户名删除所有数据
     */
    public void deleteDataForOneMobileDB() {
        String username;
      if (Config.isUserLogined()) {
            username = Config.getUserName();
        } else {
            username = "robot";
        }
        try {
            // 删除指定的信息，类似delete User where 'id' = id ;
            DeleteBuilder<OneMobileDB, Integer> deleteBuilder = mOneMobileDBDao
                    .deleteBuilder();
            deleteBuilder.where().eq("username", username);
            deleteBuilder.delete();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    /**
     * 根据用户名删除所有数据
     */
    public void deleteDataForOneMobileDBByID(String id) {
        String username;
        if (Config.isUserLogined()) {
            username = Config.getUserName();
        } else {
            username = "robot";
        }
        try {
            // 删除指定的信息，类似delete User where 'id' = id ;
            DeleteBuilder<OneMobileDB, Integer> deleteBuilder = mOneMobileDBDao
                    .deleteBuilder();
            deleteBuilder.where().eq("id", id);
            deleteBuilder.delete();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    // 本地数据库缓存
    public void getDataForOneMobileDB() {
        String username;
        if (Config.isUserLogined()) {
            username =Config.getUserName();
        } else {
            username = "robot";
        }
        OneMobileDB oneMobileDB = new OneMobileDB();
        oneMobileDB.setUsername(username);
        mOneMobileDBDao = LFYApplication.getHelper(mContext).getOneMobileDao();
        if (null != mOneMobileDBDao) {
            try {
                @SuppressWarnings("rawtypes")
                QueryBuilder builder = mOneMobileDBDao.queryBuilder();
                builder.where().eq("username", username);
                mOneMobileDBList = builder.query();
            } catch (SQLException e) {
                mOneMobileDBList = null;
            }
        }
        if (null != mOneMobileDBList && mOneMobileDBList.size() > 0) {
            for (int i = 0; i < mOneMobileDBList.size(); i++) {
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("text", mOneMobileDBList.get(i).getText());
                map.put("translation",
                        mOneMobileDBList.get(i).getTranslation());
                map.put("voiceurl",mOneMobileDBList.get(i).getVoiceurl());
                map.put("from", mOneMobileDBList.get(i).getDirection());
                map.put("id", mOneMobileDBList.get(i).getId());
                mList.add(map);
            }
        }
    }
}
